<DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <script>
        function postData(data) {
            // Default options are marked with *
            return fetch(data.url, data)
            .then(response => response.json()) // parses response to JSON
        }

        const AK = "CEri2stA9yUu6YsGNeSldNoZ"
        const SK = "CyKQhP3FNqXz5FuXezgvNi6TjXaELbFG"

        async function main() {
            var options = {
                'method': 'POST',
                'url': 'https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token=' + await getAccessToken(),
                'headers': {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json'
                },
                body: JSON.stringify({
                    "from": "en",
                    "to": "zh",
                    "q": "hello"
                })

            };

            request(options, function (error, response) {
                if (error) throw new Error(error);
                console.log(response.body);
            });
        }
        function getAccessToken() {

            let options = {
                'method': 'POST',
                'url': 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + AK + '&client_secret=' + SK,
            }
            return new Promise((resolve, reject) => {
                postData(options).then((res)=>{
                    console.log(res)
                })
            })
        }
        // getAccessToken()


        // http://api.fanyi.baidu.com/api/trans/product/desktop?req=developer
    </script>

    <body>

    </body>

    </html>